package com.lexin.udf;

import org.apache.hadoop.hive.ql.exec.UDF;

import java.util.HashMap;
import java.util.Map;

/**
 * @program: letu
 * @description:
 * @author: XL.Gao
 * @create: 2021-01-18 09:19
 **/
public class JMHiveUDF extends UDF {

    private static Map<String, String> map = new HashMap<>();

    static {
        synchronized (map){
            if(map == null || map.size() == 0){
                map.put("Q", "0");
                map.put("W", "1");
                map.put("E", "2");
                map.put("R", "3");
                map.put("T", "4");
                map.put("Y", "5");
                map.put("U", "6");
                map.put("H", "7");
                map.put("K", "8");
                map.put("P", "9");
            }
        }
    }

    public String evaluate(String input){

        StringBuffer sb = new StringBuffer();

        if(input != null && !"".equals(input)){
            char[] nums = input.toCharArray();

            for(char num : nums){
                sb.append(map.get(String.valueOf(num)));
            }
        }

        return sb.toString();
    }

    public String role(){

        return map.toString();
    }

    public static void main(String args[]){

        JMHiveUDF jmHiveUDF = new JMHiveUDF();
        String tfString = jmHiveUDF.evaluate("WKYUWKQKYQQ");
        System.out.println(tfString);
        System.out.println(jmHiveUDF.role());
    }
}
